package com.wgw.first.user.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.wgw.first.R;
import com.wgw.first.app.MainActivity;
import com.wgw.first.base.BaseFragment;
import com.wgw.first.loginRegister.LoginActivity;
import com.wgw.first.user.activity.AllOrderActivity;
import com.wgw.first.user.activity.FinishOrderActivity;
import com.wgw.first.user.activity.ReceiveOrderActivity;
import com.wgw.first.user.activity.SendOrderActivity;
import com.wgw.first.utils.Constants;

/**
 * @author Admin
 * @version $Rev$
 * @des ${TODO}
 * @updateAuthor $Author$
 * @updateDes ${TODO}
 */
public class UserFragment extends BaseFragment {

    private ImageButton ib_login_or_register;
    private TextView tv_username;
    private TextView tv_all_order;
    private TextView tv_user_send;
    private TextView tv_user_receive;
    private TextView tv_user_finish;

    @Override
    public View initView() {
        View view = View.inflate(mContext, R.layout.user_fragment,null);
        //登录或注册按钮
        ib_login_or_register = (ImageButton) view.findViewById(R.id.ib_login_or_register);
        tv_username = (TextView) view.findViewById(R.id.tv_username);
        tv_all_order = (TextView) view.findViewById(R.id.tv_all_order);
        tv_user_send = (TextView) view.findViewById(R.id.tv_user_send);
        tv_user_receive = (TextView) view.findViewById(R.id.tv_user_receive);
        tv_user_finish = (TextView) view.findViewById(R.id.tv_user_finish);
        //如果用户已经登录，则这个按钮显示用户名
        if(Constants.ALEADYLOGIN != ""){
            //如果用户不为空，则显示用户名
            tv_username.setText(Constants.ALEADYLOGIN);

        }


        ib_login_or_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MainActivity mainactivity = (MainActivity) getActivity();
                Intent intent = new Intent(mainactivity, LoginActivity.class);
                startActivity(intent);
                mainactivity.finish();
            }
        });

        //查看全部订单
        tv_all_order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!Constants.ALEADYLOGIN.equals("")){
                    Intent intent = new Intent(mContext, AllOrderActivity.class);
                    startActivity(intent);

                }else{
                    Toast.makeText(mContext,"请先登录", Toast.LENGTH_SHORT).show();
                }

            }
        });
        //查看待发货订单
        tv_user_send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!Constants.ALEADYLOGIN.equals("")){
                    Intent intent = new Intent(mContext, SendOrderActivity.class);
                    startActivity(intent);

                }else{
                    Toast.makeText(mContext,"请先登录", Toast.LENGTH_SHORT).show();
                }


            }
        });

        //查看待收货订单
        tv_user_receive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!Constants.ALEADYLOGIN.equals("")){
                    Intent intent = new Intent(mContext, ReceiveOrderActivity.class);
                    startActivity(intent);

                }else{
                    Toast.makeText(mContext,"请先登录", Toast.LENGTH_SHORT).show();
                }

            }
        });

        //查看已完成订单
        tv_user_finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!Constants.ALEADYLOGIN.equals("")){
                    Intent intent = new Intent(mContext, FinishOrderActivity.class);
                    startActivity(intent);

                }else{
                    Toast.makeText(mContext,"请先登录", Toast.LENGTH_SHORT).show();
                }

            }
        });

        return view;
    }

}
